import { defineStore } from 'pinia';

interface children {
  title: string;
  id: number;
  components: string;
}

export interface PropsList {
  title?: string;
  id?: number;
  children?: children[];
}

export const useLayoutStore = defineStore('layout', () => {
  const leftHighlight = ref<number>(0);
  const rightHighlight = ref<number>(0);
  const moduleLeft = ref<children[]>([]);
  const moduleRight = ref<children[]>([]);
  const handoffHandle = (list: children[], id: number, type: string) => {
    if (type === 'left') {
      moduleLeft.value = list;
      leftHighlight.value = id;
    } else {
      moduleRight.value = list;
      rightHighlight.value = id;
    }
  };
  const resetData = () => {
    moduleLeft.value = [];
    moduleRight.value = [];
    leftHighlight.value = 0;
    rightHighlight.value = 0;
  };
  // 封装初始化逻辑
  const initModuleData = (module: any, initLeft: boolean = true, initRight: boolean = true) => {
    console.log(moduleLeft.value, moduleRight.value, leftHighlight.value, rightHighlight.value);
    if (initLeft && module.children.length > 0) {
      moduleLeft.value = module.children;
      leftHighlight.value = module.id;
    }
    if (initRight && module.children.length > 0) {
      moduleRight.value = module.children;
      rightHighlight.value = module.id;
    }
  };

  return {
    leftHighlight,
    rightHighlight,
    moduleLeft,
    moduleRight,
    resetData,
    initModuleData,
    handoffHandle
  };
});
